<?php

class Group {
	private $id;
	private $name;
	private $id_user;
	private $date;
	
	function __construct($id,$name, $id_user, $date){
		$this -> id = $id;
		$this -> name = $name;
		$this -> id_user = $id_user;
		$this -> date = $date;

	}

	function getGroup($db,$id){
		$result=$db->query("SELECT * FROM group WHERE gro_IDgroup = $id",2);
		$group=new Group($result[0]['gro_IDgroup'],
						 $result[0]['gro_name'], 
						 $result[0]['gro_id_user'],
						 $result[0]['gro_date']);
				
		return $group;
	
	}
	
	function insertGroup($db,$group){
		$ID 		= $group -> getID();
		$name	= $group -> getIdName();
		$id_user 	= $group -> getIdUser();
		$date 		= $group -> getDate();
		
		
		$result=$db->insert("INSERT INTO group (gro_IDgroup,gro_name,gro_id_user,gro_date)
										 VALUES($ID,'$name',$id_user,now())");
		return $result;
	}		
	
	
	function deleteGroup($db,$group){
		$ID 		= $group -> getID();
		$result = $db->delete("DELETE FROM group WHERE gro_IDgroup = $ID");
		return $result;
	}
	
	function updateGroup($db,$group)
	{
		$ID 		= $group -> getID();
		$name	    = $group -> getIdName();
		$id_user 	= $group -> getIdUser();
		$date 		= $group -> getDate();
		
		$result=$db->insert("UPDATE group SET gro_name='$name',  gro_id_user = $id_user");
		return $result;
	}
			
	
	function getID(){
		return $this -> id;
	}	
	
	function  setID($id){
		$this -> id = $id;
	}	
	
	
	function getName(){
		return $this -> name;
	}	
	
	function  setName($name){
		$this -> name = $name;
	}	
	
			
	function getIdUser(){
		return $this -> id_user;
	}
	
	function  setIdUser($id_user){
		$this -> id_user = $id_user;
	}
	
	
	function getDate(){
		return $this -> date;
	}
	
	function setDate($date){
		$this -> date = $date;
	}
	
}

?>